<?php
namespace App\Lib\Error;

/**
 * 接口返回类
 * Class Response
 * @package App\Lib\Error
 */
class Response
{

    /**
     * 正常返回结果集
     * @param string $result
     * @return array
     */
    public static function Info ($result = '') {
        return [
            'status'=>ErrorConstant::STATE_INFO,
            'error_code'=>ErrorConstant::SUCCESS_CODE,
            'message'=>ErrorConstant::SUCCESS_MESSAGE,
            'result'=> $result
        ];
    }

    /**
     * 正常返回并约定路由缓存接口数据
     * @param $result
     * @param int $cacheTime
     * @return array
     */
    public static function CacheInfo($result, $cacheTime = 3600) {
        return [
            'status'=>ErrorConstant::STATE_INFO,
            'error_code'=>ErrorConstant::SUCCESS_CODE,
            'message'=>ErrorConstant::SUCCESS_MESSAGE,
            'result'=> $result,
            'catch'=>true,
            'catch_time'=>$cacheTime
        ];
    }

    /**
     * 提示性返回，客户端输入异常
     * @param $errorCode
     * @param $errorUserTitle
     * @param $errorUserMsg
     * @param $message
     * @return array
     */
    public static function Notice ($errorCode, $errorUserTitle, $errorUserMsg, $message) {
        return [
            'status'=>ErrorConstant::STATE_NOTICE,
            'error_code'=>$errorCode,
            'error_user_title'=>$errorUserTitle,
            'error_user_msg'=>$errorUserMsg,
            'message'=>$message
        ];
    }

    /**
     * 致命性错误，客户端非法请求、服务端异常
     * @param $errorCode
     * @param $message
     * @return array
     */
    public static function FatalError ($errorCode, $message) {
        return [
            'status'=>ErrorConstant::STATE_ERROR,
            'error_code'=>$errorCode,
            'message'=>$message
        ];
    }
}
